package com.project.grenting.service.customer.impl;

import com.project.grenting.dao.customer.CustomerDao;
import com.project.grenting.pojo.Customer;
import com.project.grenting.service.customer.CustomerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Resource
    private CustomerDao customerDao ;
/*

    @Override
    public User getUserByLoginCode(String loginCode) {
        return userDao.getUserByLoginCode(loginCode);
    }
*/

    @Override
    public List<Customer> getAllCustomers() {
        return customerDao.getAllCustomers() ;
    }

    @Override
    public Customer getCustomerById(int id) {
        return customerDao.getCustomerById(id);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int addCustomer(Customer customer) {
        int success = 0 ;

        //先将用户加入用户表中
        customerDao.addCustomer(customer) ;
        System.out.println(customer.getId());

        success = 1 ;

        return success ;
    }
}
